package com.qinggeng.project.api.controller;

import com.google.common.collect.Maps;
import com.qinggeng.common.exception.CustomException;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.project.system.domain.SysDictData;
import com.qinggeng.project.system.domain.vo.GoodsLowerClassifyVO;
import com.qinggeng.project.system.service.IGoodsClassifyService;
import com.qinggeng.project.system.service.ISysDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("${apiPath}/goodsLowerClassify")
public class ApiGoodsLowerClassifyController {
    @Autowired
    private IGoodsClassifyService goodsClassifyService;
    @Autowired
    private ISysDictDataService dictDataService;

    @GetMapping("/list")
    public AjaxResult list(Long classifyId) {
       Map<String,Object> map= Maps.newHashMap();
       List<GoodsLowerClassifyVO> goodsLowerClassifyList=goodsClassifyService.selectGoodsClassifByParntId(classifyId);
       map.put("list",goodsLowerClassifyList);
        List<SysDictData> listSysDictData = dictDataService.selectDictDataByType("classify_adv_color");
        if (listSysDictData==null || listSysDictData.isEmpty()){
            throw  new CustomException("特殊分类色号为设置");
        }
        map.put("color",listSysDictData.get(0).getDictValue());
        return  AjaxResult.success(map);
    }


}
